<template>
  <div class="listWapper">
    <customDetailsTopbar title="重点设备管理" flag @back="back" />
    <div id="customScroolBox" class="listInner px-1">
      <customSearch ref="customSearch" placeholder="请输入企业名称" title="重点设备列表" :total="total" @search="handleSearch" @superSearch="openSuperSearch" />
      <div v-if="tableList.length > 0" class="common_list">
        <div v-for="(item,index) in tableList" :key="index" class="list_item" @click="goDetail(item)">
          <div class="content_area">
            <div class="number_order">{{ index + 1 }}</div>
            <div class="right_content">
              <div class="content_title" style="max-width: 100%">
                {{ item.companyName }}
              </div>
              <ul class="des-list">
                <li v-for="(des,ind) in desList" :key="des.value" class="des">
                  <i :class="'iconfont c-text-color' + ((ind % 7) + 1)" v-html="des.icon" />
                  <div class="label">{{ des.label }}：</div>
                  <div class="value">{{ item[des.value] }}</div>
                  <template v-if="des.label === '下次检验日期'">
                    <van-tag
                      v-show="item['nextTimeState'] !== ''"
                      :type="item['nextTimeState'] === '临期' ? 'warning' : 'danger'"
                    >{{ item['nextTimeState'] }}</van-tag>
                  </template>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
      <customLoadmore ref="customLoadmore" :page-num="form.pageNum" :pages="pages" @load="handlePages" />
    </div>
    <van-popup
      v-model="superSearch"
      position="right"
      :style="{ width: '90%', height: '100%' }"
      lock-scroll
      close-on-popstate
      closeable
      class="custom-van-pop"
    >
      <div class="pop-vertical-flex">
        <div class="pop-content">
          <div class="customPopCheckbox">
            <div class="checkbox-title">设备名称</div>
            <el-input v-model="form.deviceName" placeholder="请输入设备名称" size="small" style="margin-bottom: 10px" />
          </div>
          <customPopCheckbox :list="selectOptionAll['能源重点设备-设备类型']" :check-value.sync="form.deviceType" title="设备类型" />
          <customPopCheckbox :list="selectOptionAll['能源重点设备-使用状态']" :check-value.sync="form.active" title="使用状态" />
        </div>
        <div class="pop-bottom">
          <van-button type="default" @click="resetSuperSearch">清空</van-button>
          <van-button type="info" @click="handleSuperSearch">确认</van-button>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import commonList from '@/assets/mixin/commonList'
import { ImportDeviceList } from '@/api/energySources'

export default {
  mixins: [commonList],
  data() {
    return {
      total: 10,
      pages: 1,
      form: {
        deviceType: '',
        active: '',
        deviceName: '',
        companyName: '',
        pageNum: 1,
        pageSize: 10,
        companyIds: -1
      },
      desList: [
        // { label: '企业名称', value: 'companyName', icon: '&#xe790;' },
        { label: '设备类型', value: 'deviceType', icon: '&#xe791;' },
        { label: '设备名称', value: 'deviceName', icon: '&#xe791;' },
        { label: '数量', value: 'deviceNum', icon: '&#xe633;' },
        { label: '使用状态', value: 'active', icon: '&#xe6a2;' },
        // { label: '设备型号', value: 'modelNum', icon: '&#xe64e;' },
        { label: '设计使用年限', value: 'planUseYear', icon: '&#xe8d5;' },
        { label: '投运日期', value: 'putUseTime', icon: '&#xe617;' },
        { label: '下次检验日期', value: 'nextTime', icon: '&#xe685;' }
      ],
      tableList: []
    }
  },
  mounted() {
    this.getDeviceList()
  },
  methods: {
    back() {
      this.$router.push({
        path: '/staging/monitor',
        query: { ...this.$route.query }
      })
    },
    goDetail(item) {
      this.$router.push({
        path: '/staging/keyEquipmentDetail',
        query: {
          examineId: item.examineId,
          deviceType: item.deviceType
        }
      })
    },
    async getDeviceList() {
      this.$refs.customLoadmore.loadStatus = true
      // this.layout.showLoading()
      const { status, data } = await ImportDeviceList(this.form)
      if (status === 0 && data) {
        this.total = data.total
        this.tableList = this.tableList.concat(data.list)
        this.pages = data.pages
      }
      this.$refs.customLoadmore.loadStatus = false
      // this.layout.hideLoading()
    },
    handleSearch(value) {
      this.form.companyName = value
      this.form.pageNum = 1
      this.tableList = []
      this.getDeviceList()
    },
    handlePages(value) {
      this.form.pageNum = value
      this.getDeviceList()
    },
    resetSuperSearch() {
      const pageSize = this.form.pageSize
      const pageNum = this.form.pageNum
      Object.keys(this.form).forEach(val => {
        this.form[val] = ''
      })
      // 重置输入框查询
      this.$refs.customSearch.restore()
      this.form.pageSize = pageSize
      this.form.pageNum = pageNum
      this.form.companyIds = -1
    },
    handleSuperSearch() {
      this.superSearch = false
      this.form.pageNum = 1
      this.tableList = []
      this.getDeviceList()
    }
  }
}
</script>

<style lang="scss" scoped>
.checkbox-title {
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 30px;
}

.right_content{
  .des-list{
    display: flex;
    flex-wrap: wrap;
    .des{
      width: 100%;
    }
  }
}
</style>
